package com.ruicar.afs.cloud.account.common.controller;

import com.ruicar.afs.cloud.account.common.service.VoucherRuleInfoService;
import com.ruicar.afs.cloud.account.dto.atom.VoucherRuleInfoDto;
import com.ruicar.afs.cloud.account.dto.tree.RuleTreeDto;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/30 13:16
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/voucherRule")
@Api(value = "voucherRule", description = "凭证记录信息")
public class VoucherRuleController {
    private final VoucherRuleInfoService voucherRuleInfoService;
    @PostMapping("/saveRule")
    @SysLog("保存规则")
    public IResponse<VoucherRuleInfoDto> saveRuleInfo(@Validated @RequestBody VoucherRuleInfoDto voucherRuleInfoDto){
        return IResponse.success(voucherRuleInfoService.checkAndSaveRule(voucherRuleInfoDto));
    }
   @PostMapping("/checkRule")
    public IResponse<VoucherRuleInfoDto> checkRuleInfo(@Validated @RequestBody VoucherRuleInfoDto voucherRuleInfoDto){
        return IResponse.success(voucherRuleInfoService.checkRule(voucherRuleInfoDto));
    }
    @PostMapping("/loadRuleTreeById/{ruleId}")
    public IResponse<List<RuleTreeDto>> loadRuleTree(@PathVariable Long ruleId){
        return IResponse.success(voucherRuleInfoService.loadRuleTree(ruleId));
    }
}
